﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FineUI;

public partial class Manager_CompInfoAdd : System.Web.UI.PageEx
{
    private string strPageCode = "S0000D";
    private string strLoginResult = string.Empty;

    private string strQuery = string.Empty;
    private string strSelectLang = "CN";
    private int iSelectId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        int.TryParse(Convert.ToString(Request.QueryString["CompId"]), out iSelectId);
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            DataBinds();
            btnReset.OnClientClick = sfCompInfo.GetResetReference();
        }
    }
    private void DataBinds()
    {
        //////////qiu//////////////
        dpEndDate.Text = SqlHelper.MinDate.ToString("yyyy-MM-dd");
        ///////////////////////////
        if (iSelectId > 0)
        {
            Model.DbCompInfo compInfo = DalEx.DbCompInfoEx.Select(iSelectId);

            if (compInfo != null)
            {
                dpEndDate.Visible = compInfo.CCode.Equals("HomeEvents", StringComparison.InvariantCultureIgnoreCase) || compInfo.CCode.Equals("YiGongBaoMing", StringComparison.InvariantCultureIgnoreCase) || compInfo.CCode.Equals("BaoMing", StringComparison.InvariantCultureIgnoreCase);
                hfCompId.Text = compInfo.CId.ToString();
                txtName.Text = compInfo.CName;
                txtName.Readonly = true;
                txtCode.Text = compInfo.CCode;
                txtCode.Readonly = true;
                txtKeywords.Text = compInfo.CKeywords;
                txtDescription.Text = compInfo.CDescription;
                cboxStatus.Checked = Convert.ToBoolean(compInfo.CStatus);
                dpEndDate.Text = compInfo.CEndDate.ToString("yyyy-MM-dd");
                PageContext.RegisterStartupScript(String.Format("updateUEditor({0});", JsHelper.Enquote(HttpUtility.HtmlDecode(compInfo.CNotes))));
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        short sStatus = 0;
        int iSelectCompId = 0;
        DateTime dtEndDate = SqlHelper.MinDate;
        string strResult = string.Empty;
        string strName = SqlHelper.String(txtName.Text.Trim());
        string strCode = SqlHelper.String(txtCode.Text.Trim());
        string strKeywords = SqlHelper.String(txtKeywords.Text.Trim());
        string strDescription = SqlHelper.String(txtDescription.Text.Trim());
        string strEndDate = SqlHelper.String(dpEndDate.Text);
        if (dpEndDate.Visible)
            DateTime.TryParse(strEndDate, out dtEndDate);
        sStatus = Convert.ToInt16(cboxStatus.Checked);
        int.TryParse(SqlHelper.String(hfCompId.Text), out iSelectCompId);
        string strNotes = HttpUtility.HtmlEncode(Request.Form["UEditor1"]);

        Model.DbCompInfo compInfo = null;
        compInfo = new Model.DbCompInfo();
        compInfo.CId = iSelectCompId;
        compInfo.CName = strName;
        compInfo.CCode = strCode;
        compInfo.CAddTime = DateTime.Now;
        compInfo.CDescription = strDescription;
        compInfo.CKeywords = strKeywords;
        compInfo.CStatus = sStatus;
        compInfo.CNotes = strNotes;
        compInfo.CEndDate = dtEndDate;
        if (DalEx.DbCompInfoEx.InsertEx(compInfo, ref strResult) > 0)
        {
            DataBinds();
            Alert.Show("企业信息编辑成功！", MessageBoxIcon.Information);
        }
        else
        {
            Alert.Show("抱歉，企业资料编辑失败！", MessageBoxIcon.Warning);
        }
    }
    protected void btnLoadData_Click(object sender, EventArgs e)
    {
        if (iSelectId > 0)//如果产品ID>0时绑定产品属性
        {
            Model.DbCompInfo compInfo = DalEx.DbCompInfoEx.Select(iSelectId);
            if (compInfo != null)
            {
                PageContext.RegisterStartupScript(String.Format("updateUEditor({0});", JsHelper.Enquote(HttpUtility.HtmlDecode(compInfo.CNotes))));
            }
        }
    }
}
